﻿function deleteFile(id_sitio, file_name, url_sitio) {
    document.getElementById("deleteButton_" + file_name).onclick = null;
    $.post(url_sitio, { idSitio: id_sitio, fileName: file_name },
                function (data) {
                    if (data.success) {
                        document.getElementById("file_delete_" + file_name).innerHTML = data.message;
                    } else {
                        document.getElementById("deleteButton_" + file_name).onclick = function(){ deleteFile(id_sitio,file_name); return false; };
                        alert(data.message);
                    }
                }, "json");
}

$(function () {
    $('#file_upload').button();
    $('#file_upload').fileUploadUI({
        uploadTable: $('#files'),
        buildUploadRow: function (files, index, handler) {
            return $('<tr><td>' + files[index].name + '<\/td>' +
                         '<td class="file_upload_progress"><div><\/div><\/td>' +
                         '<td class="file_upload_cancel">' +
                              '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                              '<\/button><\/td><\/tr>');
        },
        buildDownloadRow: function (file, handler) {
            return $('<tr><td class="file_preview"></td><td>' + file.name + '<\/td><\/tr>');
        }
    });

    $("#file_upload").animate({opacity:1}, 500);

});